﻿@{
    ViewBag.Title = "Site Resources Manager";
}
<br />
<h2>Label Translation Manager</h2>
<br />
<img src="@Url.Content("~/Areas/Admin/Content/themes/admin/img/general/warning.png")" alt="Warning">
Your changes will be appear <b>directly</b>. There is no draft or etc. version for these properties
<br />
<img src="@Url.Content("~/Areas/Admin/Content/themes/admin/img/general/warning.png")" alt="Warning">
You can change these properties via Site Management menu
<br />
<br />
<div>
    <form action="/" method="post" id="searchform" onsubmit="return false">
        @Html.DropDownList("dropDownList", new[]
        { 
            new SelectListItem { Text="--Please Select--", Value="PleaseSelect" },
            new SelectListItem { Text="Member Area", Value="SCA" },
            //new SelectListItem { Text = "Live Application Process", Value = "LAP" }, 
            new SelectListItem { Text = "Content Management System(CMS)", Value = "CMS" },
            new SelectListItem { Text = "Common Texts", Value = "GLB" },
            //new SelectListItem { Text = "Live Chat", Value = "CHAT" } 
        },  new { onChange = "templateChange()" })
    <label>You can use search box for finding text easily</label>
    @Html.TextBox("searchBox", null, new { onkeypress = "if (window.event && window.event.keyCode == 13) {templateChange();} "})
    <input type="submit" name="name" value="Search" onclick="templateChange()" />
    <input type="submit" name="name" value="Clear" onclick="resetForm()" />
    </form>
    @(Html.Telerik().Grid<Century.Model.TranslationText>()
            .Name("Grid")
            .DataKeys(keys => keys.Add(c => c.Id))

            .Columns(columns =>
            {
                columns.Bound(c => c.Id).Hidden().ReadOnly();
                columns.ForeignKey(c => c.SiteId, (System.Collections.IEnumerable)ViewBag.AccessibleSites, "Id", "Name"); //.Sortable(true).Hidden(true);
                columns.Bound(c => c.TranslationKey).ReadOnly().Encoded(false).Width(300);
                columns.Bound(c => c.TranslationValue).Encoded(false).Width(700);
                columns.Command(c =>
                {
                    c.Edit().ButtonType(GridButtonType.Image);
                }).Width(50);
            })
            .ClientEvents(clientEvents =>
            {
                clientEvents.OnEdit("editClick");
                clientEvents.OnDataBinding("dataBinding");
                clientEvents.OnSave("onSave");
            })
            .DataBinding(databinding => databinding.Ajax().Select("GetTextList", "TranslationTextManager").Update("UpdateText", "TranslationTextManager"))
            .Groupable()
            .Editable(editing => editing.Mode(GridEditMode.PopUp).FormHtmlAttributes(new { style = "width:100px" }))
            .Pageable(c => c.PageSize(100))
            .Scrollable(c => c.Height("600px"))
            .Resizable(config =>
            {
                config.Columns(true);
            })
            .Reorderable(config =>
            {
                config.Columns(true);
            })
            .ColumnContextMenu()
    )
</div>
<script type="text/javascript">

    function editClick(e) {
        $('.t-html').click('TranslationValue', showHtml);

        $(e.form).closest(".t-window-content").width(600).height(360);
        var popup = $("#" + e.currentTarget.id + "PopUp");
        popup.css({ "left": ($(window).width() / 2 - $(popup).width() / 2) + "px", "top": ($(window).height() / 2 - $(popup).height() / 2) + "px" });

        $('#TranslationKey')[0].readOnly = 'true';
        $('.editor-label:eq(1)').hide();
        $('.editor-label:eq(0)').hide();
        $('#Gridform .t-input').hide();
        $('#Gridform .t-dropdown-wrap').hide();
    }

    function onSave() {
        templateChange();
    }

    function onDropDownListChange(e) {
        $.ajax({
            type: "post",
            url: '@Url.Action("CountrySiteChange", "CountrySiteSelector")',
            data: { selectedCountrySiteId: e.value
            },
            dataType: "html",
            success: function (msg) {
                $("#Grid").data("tGrid").rebind();
            },
            error: function (msg) {
                alert('Error on changing country site');
            }
        });
    }

    function templateChange() {
        var grid = $("#Grid").data("tGrid");
        var currentPage = grid.currentPage;
        var pageCount = grid.totalPages(grid.total);
        // reload
        grid.rebind();
        // current page issues
        currentPage = (currentPage <= pageCount) ? currentPage : 1;
        grid.pageTo(currentPage);
    }

    function dataBinding(args) {
        var applicationName = $('#dropDownList').val();
        var templateName = $('#searchBox').val();
        args.data = $.extend(args.data, { templateName: templateName, applicationName: applicationName });
    }

    function resetForm() {
        $('#searchBox').val("");
        $('#dropDownList').val("PleaseSelect");
        templateChange();  
    }

</script>
